package com.ethan.cj.ssm.dao;

import com.ethan.cj.ssm.cache.RedisCacheImpl;
import com.ethan.cj.ssm.dao.provider.TestDaoProvider;
import com.ethan.cj.ssm.entity.TestEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
//@CacheNamespace(implementation= RedisCacheImpl.class)
public interface TestDao {

    @Select("SELECT * FROM `user` WHERE `username` = #{name}")
    @Results(value = {
            @Result(property = "username", column = "username"),
            @Result(property = "password", column = "password")
    })//property和column完全一致时可省略此注解
    TestEntity selectTestEntityByName(String name);

    @Select("SELECT * FROM `user` WHERE `id` = #{id}")
    TestEntity selectTestEntityById(int id);

    @Select("SELECT * FROM `user`")
    List<TestEntity> list();

    List<TestEntity> pageList(@Param("name") String name, @Param("offset") int offset, @Param("limit") int limit);

    @SelectProvider(type = TestDaoProvider.class, method = "count")
    int count(@Param("name") String name);

    @Delete("DELETE FROM `user` WHERE id = #{id}")
    int delete(int id);

    @Insert("INSERT INTO `user` (`username`, `password`) VALUES (#{username}, #{password})")
    int insert(TestEntity te);

    @Update("UPDATE `user` SET `password` = #{password} WHERE `id` = #{id}")
    int update(TestEntity te);
}
